<?php
use yii\helpers\Url;
?>
<div class="row-content am-cf">
    <div class="row">

        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">编辑居民</div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog"></a>
                    </div>
                </div>
                <div class="widget-body am-fr">

                    <form class="am-form tpl-form-border-form tpl-form-border-br">
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">用户名 </label>
                            <div class="am-u-sm-9">
                                <input type="text" class="tpl-form-input" id="username" placeholder="请输入用户名" value="<?=$customer->username?>" readonly="1">
                                <small>初始密码123456</small>
                            </div>
                        </div>


                        <div class="am-form-group">
                            <label for="user-phone" class="am-u-sm-3 am-form-label">区域 </label>
                            <div class="am-u-sm-9">
                                <select data-am-selected="{searchBox: 0}" id="area" style="display: none;">
                                    <?php foreach ($areas as $area) {
                                        $selected="";
                                        if($area['id']==$customer->areaid){
                                            $selected="selected='true'";
                                        }

                                        echo "<option ".$selected." value=\"".$area['id']."\">".$area['areaname']."</option>";
                                    }?>

                                </select>

                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">住址 </label>
                            <div class="am-u-sm-9">
                                <input type="text" id="address" placeholder="输入住址" value="<?=$customer->address?>">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">姓名 </label>
                            <div class="am-u-sm-9">
                                <input type="text" id="realname" placeholder="输入姓名" value="<?=$customer->realname?>">
                            </div>
                        </div>


                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-3 am-form-label">联系电话 </label>
                            <div class="am-u-sm-9">
                                <input type="tel" id="phone" placeholder="请输入电话" value="<?=$customer->phone?>">
                                <div>

                                </div>
                            </div>
                        </div>



                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button id="submit" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
                            </div>
                        </div>
                    </form>
                    <script>
                        $("#submit").click(function(){
                            var username= $("#username").val();
                            var address=$("#address").val();
                            var realname = $("#realname").val();
                            var phone = $("#phone").val();
                            var areaid=$("#area").val();
                            if(username==''){
                                alert("用户名不能为空！");
                                return ;
                            }
                            if(address==''){
                                alert("地址不能为空！");
                                return ;
                            }
                            if(realname==''){
                                alert("姓名不能为空！");
                                return ;
                            }
                            if(!checkPhone(phone)){
                                alert("手机号不正确！");
                                return ;
                            }
                            $.ajax({
                                url:"<?=Url::to(['customer/edit-customer'])?>",
                                data:"id=<?=$customer->id?>&address="+address+"&areaid="+areaid+"&realname="+realname+"&phone="+phone,
                                type:'post',
                                dataType:'json',
                                success:function(data){
                                    if(data.status){
                                        alert(1);
                                    }else{
                                        alert(data.msg);
                                    }
                                },
                                error:function(){
                                    alert("系统繁忙");
                                }
                            })
                        })

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>